package com.jishi.gouwuche.conf;

import cn.hutool.json.JSONUtil;

import com.jishi.gouwuche.common.Result;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import java.io.IOException;

public class MyLoginFilter extends FormAuthenticationFilter {
    @Override
    protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().write(JSONUtil.toJsonStr(Result.error("未登录")));
        response.getWriter().flush();
        return false;
    }

//    @Override
//    protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
//        Subject subject=this.getSubject(request,response);
//        HttpServletRequest httpRequest=(HttpServletRequest) request;
//        String requestUrl=httpRequest.getRequestURI();
//        String[] arr=requestUrl.split("/");
//        if (!subject.isPermitted(arr[1])){
//            return false;
//        }
//        return true;
//    }
}
